package com.huazi.user.registration.service.Imp;

import com.huazi.user.registration.dao.LoginI;
import com.huazi.user.registration.dao.User_Disease_infoi;
import com.huazi.user.registration.dao.imp.LoginImpl;
import com.huazi.user.registration.dao.imp.User_Disease_infoImpl;
import com.huazi.user.registration.entity.Ct_user;
import com.huazi.user.registration.entity.DiseaseInfo;
import com.huazi.user.registration.entity.User;
import com.huazi.user.registration.service.LoginServiceI;
import com.huazi.util.SessionUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LoginService implements LoginServiceI {
    public boolean login(String pwd, String account) {
        Map<String,Object> map=new HashMap<>();
        if(account.length()==18){
            map.put("account",account);
        }else {
            map.put("ids",Integer.parseInt(account));
        }
        map.put("pwd",pwd);
        Integer register = SessionUtil.getSession().getMapper(LoginI.class).register(map);
        System.out.println(register);
            if(register==1){
                    return true;
                }
        return false;
    }

    @Override
    public User selectUser(String account) {
        User result = SessionUtil.getSession().getMapper(LoginI.class).result(Integer.parseInt(account));

        return result;
    }

    @Override
    public List<DiseaseInfo> selectDis(Integer userId) {
        User_Disease_infoi info = new User_Disease_infoImpl();
        return info.selectInfo(userId);
    }

    @Override
    public List<Ct_user> selectCt(String account) {
      return  SessionUtil.getSession().getMapper(LoginI.class).resultCt("60002");
    }

}
